//玩家命令行插件

string author = "Live";
string pluginName = "Player_Commands 玩家命令";
string version = "1.1";

// 插件初始化
void OnPluginInit()
{
	// 设置插件信息
	PluginData::SetAuthor(author);
	PluginData::SetName(pluginName);
	PluginData::SetVersion(version);

	// 提示
	ThePresident.InfoFeed("插件:"+pluginName+"| 版本:"+version+"| 作者:"+author,false);
    
    Events::Player::PlayerSay.Hook( @PlayerSay );
}

// 当玩家say
HookReturnCode PlayerSay(CTerrorPlayer@ pPlayer, CASCommand@ pArgs)
{
	string arg = pArgs.Arg( 1 );
	string arg1 = "";
	string arg2 = "";

	// 切分字符串(这样就可以用空格传一个命令参数了)
	int subIndex = arg.findFirst(" ",0);
	if(not (subIndex < 0)){
		arg1 = arg.substr(0,subIndex);
		arg2 = arg.substr(subIndex+1,-1);
		//Chat.PrintToChat(all,""+arg1+"|"+arg2);
	}else{
		arg1 = arg;
	}

	if( Utils.StrEql( arg1, "!k" ) ){
			int TeamNumber = pPlayer.GetTeamNumber();
			if(TeamNumber == 2){
				Engine.RunConsoleCommand( "admin slay !" + pPlayer.entindex() );
				return HOOK_HANDLED;
			}else{
				Chat.PrintToChat(pPlayer,"{gold}[{green}Server{gold}]{white}:只有做人的时候才能自杀！（Suicide is only possible when in the survivor camp）");
			}
	}else if( Utils.StrEql( arg1, "!fh" ) ){
		if( AdminSystem.AdminExist(pPlayer) ){
			if( not Utils.StrEql( arg2, "" ) ){
				CTerrorPlayer@ splayer = ToTerrorPlayer( parseInt(arg2,10,0) );
				// 修改被复活玩家的游戏阵营
				splayer.ChangeTeam( TEAM_SURVIVOR );
				// 复活玩家
				splayer.Respawn();
				Chat.PrintToChat(all,"{hotpink}管理员使用命令复活了["+splayer.GetPlayerName()+"]");
			}else{
				// 修改被复活玩家的游戏阵营
				pPlayer.ChangeTeam( TEAM_SURVIVOR );
				// 复活玩家
				pPlayer.Respawn();
			}
		}else{
			Chat.PrintToChat(pPlayer,"您不是管理员，无法执行复活命令");
		}
	}
	return HOOK_CONTINUE;
}